<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
</head>
<body>
<!-- 导航栏 -->
<div class="nav">
    <!-- logo -->
    <img src="img/cat.jpg" alt="">
    <!-- 标题 -->
    <span class="title">Java 在线OJ 系统</span>
    <!-- 空白的占位符 -->
    <span class="spacer"></span>
    <!-- 右侧的几个链接 -->
    <a class="navbar-brand font-weight-bold" href="index.html">主页</a>
    <a class="navbar-brand font-weight-bold" href="javascript:void(0);"  onclick=logout()>注销</a>
</div>

<!-- 登录页面的页面容器, 为了和其他页面样式区分开, 使用不同的类名 -->
<div class="login-container" >
    <div class="login-dialog" style="height: 380px">

            <!-- 标题 -->
            <h3>登录</h3>
            <!-- 输入用户名 -->
            <div class="row">
                <span>用户名</span>
                <input type="text" id="username" name="username">
            </div>
            <!-- 输入密码 -->
            <div class="row">
                <span>密码</span>
                <input type="password" id="password" name="password">

            </div>

        <!-- 提交按钮 -->
        <div class="row submit-row">
            <!-- <button id="submit">提 交</button> -->
            <input id="submit" type="submit" onclick=log() value="登陆">
        </div>

        <br>

                <a href="phoneLogin.html" target="_blank" class="a1" style="color:blue;text-decoration: none">&nbsp&nbsp&nbsp&nbsp手机号验证码登陆&nbsp&nbsp&nbsp&nbsp</a>

                <a href="register.html" target="_blank" class="a1" style="color:blue;text-decoration: none">&nbsp&nbsp&nbsp&nbsp注册账号&nbsp&nbsp&nbsp&nbsp</a>

                <a href="missPassword.html" target="_blank" class="a1" style="color:blue;text-decoration: none">&nbsp&nbsp&nbsp&nbsp忘记密码&nbsp&nbsp&nbsp&nbsp</a>





    </div>
</div>

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>


    function log() {
        //1、获取用户名和密码的值
         let username = document.querySelector("#username");
         let password = document.querySelector("#password");
         // console.log(username.value);
         // console.log(password.value);

        //2、发送ajax请求
        $.ajax({
            url:"state/login"+"?username="+username.value+"&password="+password.value,
            type:"POST",
            success:function (data,status) {
                alert(data.message);
                if(data.state===3004){// 登陆成功，跳转主页
                    location.href="index.html";
                }
            }
        })

    }

    function logout() {
        $.ajax({
            url:"state/logout",
            type:"POST",
            success:function (data,status) {
                if(data.state===5001){
                    alert(data.message);
                }else if(data.state===5002){
                    alert(data.message);
                    location.href="login.html";
                }
            }
        })
    }
</script>

</body>



</html>